package edu.csumb.itcd.teammario;

import java.awt.Point;
import java.util.ArrayList;
import java.util.Random;

public abstract class EnemyFactory {

	private static Random random = new Random();
	protected static int enemyMin;
	protected static int currentLevel;
	private static boolean levelEnd = false;
	private static boolean levelStart = false;
	protected static ArrayList<ArrayList<Enemy>> wave = new ArrayList<ArrayList<Enemy>>();
	protected static EnemyFactory level;
	
	
	public abstract boolean loadNextLevel();
	
	public abstract void loadLevel();
	
	public static void start()
	{
		level = new Level1();
		levelStart = true;
	}
	
	public static void restartLevel()
	{
		level.loadLevel();
		levelStart = true;
	}
	
	public static boolean nextLevel()
	{
		levelEnd = false;
		levelStart = true;
		
		if (level.loadNextLevel())
		{
			Player.setCurrentHealth(Player.getMaxHealth());
			return true;
		}
		
		return false;
	}
	
	public static int getCurrentLevel()
	{
		return currentLevel;
	}	
	
	public static void runLevel(ArrayList<Enemy> enemyArray)
	{
		if (enemyArray.size() < enemyMin && wave.size() > 0)
		{
			for (int i = 0; i < wave.get(0).size(); i++)
			{
				enemyArray.add(wave.get(0).get(i));
			}
			wave.remove(0);
		} else if (levelStart && wave.size() == 0)
		{
			levelEnd = true;
			levelStart = false;
		}
	}
	
	protected static Point spawnEnemyPoint()
    {
        int temp;
        int quadrant;
        Point spawnPoint = new Point(0,0);
            quadrant = random.nextInt(4) + 1;

            
            if (quadrant == 1)
            {//Left
                temp = random.nextInt(35);
                temp *= -1;
                spawnPoint.x = temp;
                
                temp = random.nextInt(600);
                temp += 25;
                spawnPoint.y = temp;
            }
            else if (quadrant == 2)
            {//Top
                temp = random.nextInt(800);
                temp += 1;
                spawnPoint.x = temp;
                
                temp = random.nextInt(35);
                temp *= -1;
                spawnPoint.y = temp;
            }
            else if (quadrant == 3)
            {//Right
                temp = random.nextInt(35);
                temp += 800;
                spawnPoint.x = temp;
                
                temp = random.nextInt(600);
                temp += 25;
                spawnPoint.y = temp;
            }
            else
            {//Bottom
                temp = random.nextInt(800);
                temp += 1;
                spawnPoint.x = temp;
                
                temp = random.nextInt(35);
                temp += 625;
                spawnPoint.y = temp;
            }
            
            return spawnPoint;
    }
	
	public static boolean isLevelEnded()
	{
		return levelEnd;
	}
}
